import { http } from "@/utils/http";

export interface ResultProps<T> {
  status: string;
  data: T;
  message: string;
  time: Date;
  pageCount: number;
  error: null;
  need_update: null;
  code: number;
  token: string;
}

export type GetListParamProp<T> = {
  start_page: number;
  size: number;
} & { [P in keyof T]?: T[P] };

export interface Data {
  id: number;
  business_id: number;
  account: string;
  password: string;
  icon: null;
  nickname: null;
  realname: string;
  email: string;
  phone: string;
  create_time: Date;
  department: null;
  post: null;
  type: number;
  account_region_status: boolean;
  account_super_status: boolean;
  account_svip_status: boolean;
  log_share_status: boolean;
  publish_status: number;
  update_time: Date;
  verfity_status: number;
  department_name: null;
  post_name: null;
  accountstore_list: null;
}

export type UserResult = ResultProps<Data>;

export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<UserResult>("post", "/account/login", {
    data
  });
};

/** 刷新`token` */
export const refreshTokenApi = (data?: object) => {
  return http.request<UserResult>("post", "/refresh-token", { data });
};

// 获取省市树
export const getProvinceCity = (data?: object) => {
  return http.request<ResultProps<any[]>>("get", "/provinceCity", { data });
};
